package org.example.shop.api;

import org.example.shop.dao.GoodsSearchDao;
import org.example.shop.pojo.Goods;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class SearchController {
    @Resource
    private GoodsSearchDao goodsSearchDao;

    @GetMapping("/goods/search")
    public Page<Goods> search(String title,
                              @RequestParam(name = "page", defaultValue = "1") Integer page,
                              @RequestParam(name = "size", defaultValue = "10") Integer size) {
        return goodsSearchDao.findByTitle(title, PageRequest.of(page, size));
    }
}
